//
// Created by Tony on 2024/5/19.
//

#ifndef COMMON_ERROR_RECORDER_H
#define COMMON_ERROR_RECORDER_H

#include <cstdint>
#include <string>

class ErrorRecorder {
    static constexpr int ERR_MSG_LENGTH = 256;
    int16_t errCode = -1;
    std::string errMsg;

public:
    virtual ~ErrorRecorder() = default;

    void setErrCode(int16_t code) { this->errCode = code; }
    int16_t getErrCode() const { return errCode; }

    void setErrMsg(const std::string& message) { this->errMsg = message; }

    template <typename... Types> void setErrMsg(const char* fmt, Types... args) {
        char buf[ERR_MSG_LENGTH];
        snprintf(buf, sizeof(buf), fmt, args...);
        errMsg = std::string{buf};
    }

    std::string getErrMsg() const { return errMsg; }
};

#endif // COMMON_ERROR_RECORDER_H
